﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Business.Util;
using ZLCMS.Data.Model;

namespace ZLCMS.Web.SystemManage.Template.Web
{
    public partial class WebManager : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected int UserTemplateId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);


            int pageSize = _framePage.IsAjaxPagerPostBack ? _framePage.PageSize : 20;
            int pageIndex = _framePage.IsAjaxPagerPostBack ? _framePage.PageIndex : 1;

            UserTemplateId = TemplateUtil.GetUserTemplateId(UserKit.GetUserAccountWithoutException());
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                _framePage.RecordCount = Convert.ToInt32(session.CreateQuery("select count(*) from CmsUserTemplatePage where UserTempId=:tid ")
                    .SetParameter("tid", UserTemplateId)
                    .UniqueResult());

                repeater1.DataSource = session.CreateQuery("from CmsUserTemplatePage where UserTempId=:tid order by PageLevel, Sort")
                    .SetParameter("tid", UserTemplateId)
                    .SetMaxResults(pageSize)
                    .SetFirstResult((pageIndex - 1) * pageSize)
                    .List<ZLCMS.Data.Model.CmsUserTemplatePage>();
            }
            repeater1.DataBind();

        }

        protected string GetContent(object item)
        {
            CmsUserTemplatePage upage = item as CmsUserTemplatePage;
            string result = "<a style='color:#0C0C0C'>管理</a>";
            //""
            //if (upage.Kind != "default")
            {
                result = "<a href='/SystemManage/Template/Web/";
                if (upage.Kind == "list")
                {
                    result += "DocList.aspx";
                }
                else
                {
                    result += "DocDetail.aspx";
                }
                result += "?src=man&tempid=" + upage.Id +  "'";
                result += " target='navTab' rel='";

                if (upage.Kind == "list")
                {
                    result += "DocList";
                }
                else
                {
                    result += "DocDetail";
                }
                result += "' title='" + upage.Name + "'>内容管理</a>";

            }

            return result;

        }

    }
}